package com.yyh.synctool.client.init;

import com.yyh.synctool.client.component.ThisApplicationContext;
import com.yyh.synctool.client.property.PageProperties;
import com.yyh.synctool.client.util.BrowserLauncher;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;

/**
 * 应用启动初始化
 * @author xuan
 * @date 2021/12/3
 */
@Slf4j
//@Component
public class ApplicationInit implements ApplicationRunner
{
    private PageProperties pageProperties;
    private ThisApplicationContext thisApplicationContext;

    @Autowired
    public ApplicationInit(PageProperties pageProperties, ThisApplicationContext thisApplicationContext) {
        this.pageProperties = pageProperties;
        this.thisApplicationContext = thisApplicationContext;
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        log.info("[{}]应用启动成功，应用数据根目录：'{}'",
                thisApplicationContext.getApplicationName(), thisApplicationContext.getRootDir());
        log.info("应用访问主页：'{}'", pageProperties.getHome());

        // 应用启动时打开操作界面的url链接
        BrowserLauncher.openURL(pageProperties.getHome());
    }
}
